import axios from 'axios';
import queryString from 'qs';
import _ from 'lodash';
import { downloadFile } from '@util/download-file';

export const getLogList = filter => {
  const formatedFiler = _.pickBy(filter, value => Boolean(value));
  const query = queryString.stringify(formatedFiler);
  return axios.get(`/api/log/listLog?${query}`);
};

export const deleteAllLogs = () => {
  return axios.post('/api/log/deletAllLogs');
};

export const exportLoginLog = filter => {
  const formatedFiler = _.pickBy(filter, value => Boolean(value));
  const query = queryString.stringify(formatedFiler);
  return axios.get(`/api/log/exportLogin?${query}`);
};

export const exportOperateLog = filter => {
  const formatedFiler = _.pickBy(filter, value => Boolean(value));
  const query = queryString.stringify(formatedFiler);
  return axios.get(`/api/log/exportOperate?${query}`);
};

export const showLoginLog = () => {
  return axios.get('/api/log/showLogin');
};

export const showOperateLog = () => {
  return axios.get('/api/log/showOperate');
};

export const downloadLogin = filename => {
  return downloadFile('get', `/api/log/downloadLogin?filename=${filename}`);
};

export const downloadOperate = filename => {
  return downloadFile('get', `/api/log/downloadOperate?filename=${filename}`);
};

export const deleteLoginLog = filename => {
  return axios.post('/api/log/deleteLogin', { filename });
};

export const deleteOperateLog = filename => {
  return axios.post('/api/log/deleteOperate', { filename });
};
